﻿using Sys.Core.Gen;
using Sys.Core.Sys;
using Sys.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class New : System.Web.UI.Page
{
    public SysDictionary dic { get; set; }
    public GenNew model { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["id"];

            if (!string.IsNullOrEmpty(id))
            {
                model = NewBll.I.GetByKey(id);

                if (model != null)
                {
                    dic = DictionaryBll.I.GetByKey(model.DictionaryID);

                    if (dic == null) { dic = new SysDictionary(); }

                    Home mas = Master as Home;

                    mas.SetHead(model.Name, model.Keywords, model.Description);
                }
                else { model = new GenNew(); }
            }
            else { model = new GenNew(); dic = new SysDictionary(); }
        }
    }

    public string GetPrev(string tag, GenNew item)
    {
        string temp = "<li><span>上一篇：</span> ";

        if (item != null || string.IsNullOrEmpty(tag))
        {
            var prve = NewBll.I.NewsByTag(tag).Where(m => m.UpdateTime > item.UpdateTime).OrderBy(m => m.UpdateTime).FirstOrDefault();

            if (prve != null)
            {
                temp += "<a href='New.aspx?id=" + prve.ID + "'>" + prve.Name + "</a>";
            }
            else { temp += "<a href='#'>没有了</a>"; }
        }
        else { temp += "<a href='#'>没有了</a>"; }

        return temp + "</li>";
    }

    public string GetNext(string tag, GenNew item)
    {
        string temp = "<li><span>下一篇：</span> ";

        if (item != null || string.IsNullOrEmpty(tag))
        {
            var netx = NewBll.I.NewsByTag(tag).Where(m => m.UpdateTime < item.UpdateTime).FirstOrDefault();

            if (netx != null)
            {
                temp += "<a href='New.aspx?id=" + netx.ID + "'>" + netx.Name + "</a>";
            }
            else { temp += "<a href='#'>没有了</a>"; }
        }
        else { temp += "<a href='#'>没有了</a>"; }

        return temp + "</li>";
    }
}